package com.yiwei.hdb.activity;

import android.os.Bundle;
import android.text.TextUtils;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.yiwei.hdb.R;
import com.yiwei.hdb.constant.Const;
import com.yiwei.hdb.event.OnCloseFloatMsg;

import org.greenrobot.eventbus.EventBus;

public class LookPayProcessActivity extends BaseActivity {

    String url;
    WebView web_view;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setBaseContentView(R.layout.activity_look_pay_process);
        baseInitView(this, "LookPayProcessActivity", Const.ViewType.ACTIVITY);
        initView();

    }

    private void initView() {
        setBackIntent();
        String title = getIntent().getStringExtra("title");
        if (title != null) {
            setTitleText(title);
        } else {
            setTitleText("详情");
        }
        url = getIntent().getStringExtra("process_url");
        if (TextUtils.isEmpty(url)) {
            return;
        }
        web_view = (WebView) findViewById(R.id.web_view);
        setWebView(url);
    }

    private void setWebView(String url) {

        if (url != null) {
            //http://192.168.51.104:8080/atguigu/json/GOODSINFO_URL.json2691
//            wbGoodInfoMore.loadUrl(Constants.GOODSINFO_URL + product_id);
            web_view.loadUrl(url);
            //覆盖WebView默认使用第三方或系统默认浏览器打开网页的行为，使网页用WebView打开
            web_view.setWebViewClient(new WebViewClient() {
                @Override
                public boolean shouldOverrideUrlLoading(WebView view, String url) {
                    //返回值是true的时候控制去WebView打开，为false调用系统浏览器或第三方浏览器
                    view.loadUrl(url);
                    return true;
                }
            });
//            web_view.setWebChromeClient(new WebChromeClient(){
//
//            });
            //启用支持javascript
            WebSettings settings = web_view.getSettings();
            settings.setJavaScriptEnabled(true);
            settings.setUseWideViewPort(true);
            settings.setBlockNetworkImage(false);//支持加载图片

            //优先使用缓存
            web_view.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
        }


    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().post(new OnCloseFloatMsg());
    }
}
